package com.stone.framework.batch.service;

import com.stone.framework.batch.entity.CaseAssign;
import com.stone.framework.batch.entity.CaseInfo;
import com.stone.framework.batch.entity.CaseState;
import com.stone.framework.batch.model.CaseAllocBO;
import com.stone.framework.batch.model.CaseAllocResultBO;
import com.stone.framework.core.exception.BusinessException;

public abstract class ExitedCaseService extends GenericCaseService {

    @Override
    protected CaseAllocResultBO doAllocate(CaseInfo currCaseInfo, CaseAllocBO caseAllocBo) {
        if (currCaseInfo == null) {
            throw new BusinessException("案件不存在或已出催");
        }
        CaseInfo closedCaseInfo = this.buildClosedCaseInfo(currCaseInfo);
        CaseState updateCaseState = this.buildUpdateCaseState(currCaseInfo, getCaseStateState());
        CaseAssign closedCaseAssign = this.buildClosedCaseAssign(currCaseInfo, getCaseAssignType());
        return new CaseAllocResultBO().closedCaseInfo(closedCaseInfo).updateCaseState(updateCaseState)
            .closedCaseAssign(closedCaseAssign).build();
    }

    protected abstract CaseAssign.Type getCaseAssignType();

    protected abstract CaseState.State getCaseStateState();

}
